package com.ruoyi.resource.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.resource.domain.ImgResource;
import com.ruoyi.resource.service.IImgResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 同步镜像数据Controller
 *
 * @author ruoyi
 * @date 2022-04-15
 */
@RestController
@RequestMapping("/resource")
public class ImgResourceController extends BaseController
{
    @Autowired
    private IImgResourceService imgResourceService;

    /**
     * 查询同步镜像数据列表
     */
    @RequiresPermissions("system:resource:list")
    @GetMapping("/list")
    public TableDataInfo list(ImgResource imgResource)
    {
        startPage();
        List<ImgResource> list = imgResourceService.selectImgResourceList(imgResource);
        return getDataTable(list);
    }

    /**
     * 导出同步镜像数据列表
     */
    @RequiresPermissions("system:resource:export")
    @Log(title = "同步镜像数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImgResource imgResource)
    {
        List<ImgResource> list = imgResourceService.selectImgResourceList(imgResource);
        ExcelUtil<ImgResource> util = new ExcelUtil<ImgResource>(ImgResource.class);
        util.exportExcel(response, list, "同步镜像数据数据");
    }

    /**
     * 获取同步镜像数据详细信息
     */
    @RequiresPermissions("system:resource:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(imgResourceService.selectImgResourceById(id));
    }

    /**
     * 新增同步镜像数据
     */
    @RequiresPermissions("system:resource:add")
    @Log(title = "同步镜像数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImgResource imgResource)
    {
        return toAjax(imgResourceService.insertImgResource(imgResource));
    }

    /**
     * 修改同步镜像数据
     */
    @RequiresPermissions("system:resource:edit")
    @Log(title = "同步镜像数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImgResource imgResource)
    {
        return toAjax(imgResourceService.updateImgResource(imgResource));
    }

    /**
     * 删除同步镜像数据
     */
    @RequiresPermissions("system:resource:remove")
    @Log(title = "同步镜像数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imgResourceService.deleteImgResourceByIds(ids));
    }
}
